package com.lg.concurrent;

import java.util.concurrent.TimeUnit;

/**

 */
public class SynchronizedTest {

    boolean  flag = true;

    Object o = new Object();
    public static void main(String[] args) {
        SynchronizedTest synchronizedTest = new SynchronizedTest();
        synchronizedTest.run();
    }
    public void run() {
        //死循环 程序停不下来
        new Thread(() -> {
            while (flag) {
                //lock 会刷新 工作内存中共享变量的 值
                synchronized (o) {

                }
            }
        }).start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            flag = false;
        }).start();
    }
}
